package com.cg.conrtoller;

import com.cg.annotation.Decrypt;
import com.cg.annotation.Encrypt;
import com.cg.entity.RespBean;
import com.cg.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {


    @GetMapping("/testEncrypt")
    @Encrypt  //添加注解才进行加密操作
    public RespBean testEncrypt() {
        User user = User.builder()
                .userName("waaaaa")
                .age(12)
                .build();
        return RespBean.ok("666666", user);
    }

    /**
     * 传入user信息必须为加密后的内容且head需设置content-type为json格式
     * @param user
     * @return
     */
    @PostMapping("/testEncryptForReq")
    @Decrypt
    public RespBean testEncryptForReq(@RequestBody User user) {
        return RespBean.ok("解密成功", user);
    }


}
